package krow.dev.addetector.model;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import krow.dev.addetector.control.Module;
import android.content.pm.PackageInfo;

public class ApplicationItem {

	private PackageInfo mPackageInfo;

	private Set<Module> mModuleSet;

	public ApplicationItem(PackageInfo packageInfo) {
		mPackageInfo = packageInfo;
		mModuleSet = new HashSet<Module>();
	}
	
	public PackageInfo getPackageInfo() {
		return mPackageInfo;
	}

	public Set<Module> getModuleSet() {
		return mModuleSet;
	}
	
	public List<Module> getModuleList(){
		List<Module> moduleList = new ArrayList<Module>();
		moduleList.addAll(mModuleSet);
		return moduleList;
	}
	
	public void addModule(Module module){
		if(!mModuleSet.contains(module)){
			mModuleSet.add(module);
		}
	}
	
	@Override
	public String toString() {
		StringBuilder stringBuilder = new StringBuilder();
		
		Iterator<Module> iterator = mModuleSet.iterator();
		while (iterator.hasNext()) {
			Module module = iterator.next();
			stringBuilder.append(module).append(", ");
		}
		
		String result = stringBuilder.toString();
		if(result != null && result.trim().length() > 2){
			result = result.substring(0, result.length() - 2);
		}
		
		return result;
	}
}
